package com.yanggu.redisson.config;

import com.fasterxml.jackson.core.type.TypeReference;
import com.yanggu.redisson.component.producer.DelayedQueueProducerComponent;
import com.yanggu.redisson.domain.OrderData;
import lombok.Data;
import org.redisson.api.RedissonClient;
import org.redisson.codec.TypedJsonJacksonCodec;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义延迟组件配置类
 */
@Data
@Configuration
public class DelayQueueProducerComponentConfig {

    @Value("${delay-queue.name1}")
    private String queueName1;

    @Value("${delay-queue.name2}")
    private String queueName2;

    @Bean("delayedQueueComponent")
    public DelayedQueueProducerComponent<String> delayedQueueComponent(RedissonClient redissonClient) {
        TypedJsonJacksonCodec codec = new TypedJsonJacksonCodec(new TypeReference<String>() {});
        return new DelayedQueueProducerComponent<>(redissonClient, queueName1, codec);
    }

    @Bean("delayedQueueComponent2")
    public DelayedQueueProducerComponent<OrderData> delayedQueueComponent2(RedissonClient redissonClient) {
        TypedJsonJacksonCodec codec = new TypedJsonJacksonCodec(new TypeReference<OrderData>() {});
        return new DelayedQueueProducerComponent<>(redissonClient, queueName2, codec);
    }

}
